﻿#region Usings&Copyright
/*================================================
 *= Reader.cs (c)2009 Eagle Eye Studios          =
 *=         Written by Florian Vick              =
 *================================================
 */
using System;
using System.Collections.Generic;
using System.Text;
using Nini.Config;
#endregion

namespace Astudio.FileManagement
{
    public class Reader
    {
        #region Variables
        /// <summary>
        /// The Path of the File which will be read.
        /// </summary>
        public string Filepath { get; private set; }
        private DotNetConfigSource reader;
        #endregion

        #region Methods
        /// <summary>
        /// Creates a new Instance of Astudio.FileManagement.Reader.
        /// </summary>
        /// <param name="Path">The Path of the File which will be read.</param>
        public Reader(string Path)
        {
            Filepath = Path;
            reader = new DotNetConfigSource(Filepath);
        }

        /// <summary>
        /// Gets the Name of the current Autorun-App.
        /// </summary>
        /// <returns></returns>
        public string GetName()
        {
            string temp;
            try
            {
                temp = reader.Configs["Settings"].GetString("MenuName", "Autorun Menü");
            }
            catch
            {
                throw new Exception("Could not read Settings/MenuName");
            }
            return temp;
        }

        /// <summary>
        /// Gets the Number of Elements in this App.
        /// </summary>
        /// <returns></returns>
        public int GetNumberOfElements()
        {
            int temp;
            try
            {
                temp = reader.Configs["Settings"].GetInt("TotalElements");
            }
            catch { throw new Exception("Could not read Settings/TotalElements"); }
            return temp;
        }

        /// <summary>
        /// Gets a string, which describes Designfile
        /// </summary>
        /// <returns></returns>
        public string GetDesign()
        {
            string temp;
            try
            {
                temp = reader.Configs["Settings"].GetString("Design");
            }
            catch { throw new Exception("Could not read Settings/Design"); }
            return temp;
        }

        /// <summary>
        /// Gets if the Window is used or not
        /// </summary>
        /// <returns></returns>
        public bool GetUseWindow()
        {
            return reader.Configs["Settings"].GetBoolean("UseWindow", true);
        }
        #endregion
    }
}
